<?php
namespace system;

/**
 * Simple router class (no configuration needed)
 * @author milena
 *
 */
class Router
{

    private $request;

    public function __construct()
    {
        $requestURI = explode('/', str_replace(array("?","="), "/", $_SERVER['REQUEST_URI']));
        $scriptName = explode('/', $_SERVER['SCRIPT_NAME']);
        for ($i = 0; $i < sizeof($scriptName); $i ++) {
            if ($requestURI[$i] == $scriptName[$i]) {
                unset($requestURI[$i]);
            }
        }
        $commandArray = array_values($requestURI);
        
        $commandName = isset($commandArray[0]) ? $commandArray[0] : null;
        $parameters = array_slice($commandArray, 1);
        $httpMethod = $_SERVER['REQUEST_METHOD'];
        
        $this->request = new Request($commandName, $parameters, $httpMethod);
    }

    public function getRequest()
    {
        return $this->request;
    }
}
